package Demo2;

import java.util.Scanner;

class Data {
	String name;
	int in_time;
	int run_time;
	int location;

	public Data(String name, int in_time, int run_time, int location) {
		this.name = name;
		this.in_time = in_time;
		this.run_time = run_time;
		this.location = location;
	}
}

public class List {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		Data[] data = new Data[3];
		int[] re_time = new int[3];
		//输入
		for (int i = 0; i < 3; i++) {
			String name = s.next();
			int in_time = s.nextInt();
			int run_time = s.nextInt();
			int location = i + 1;
			data[i] = new Data(name, in_time, run_time, location);
		}
		//判断响应比大小
		int len = 3;
		int time = 0;
		while (len > 0) {
			double level_a = 0;
			double level_b = 0;
			double level_c = 0;
			if (data[0].in_time <= time && data[0].run_time != 0) {
				level_a = 1 + (time - data[0].in_time) * 1.0 / data[0].run_time;
			}
			if (data[1].in_time <= time && data[1].run_time != 0) {
				level_b = 1 + (time - data[1].in_time) * 1.0 / data[1].run_time;
			}
			if (data[2].in_time <= time && data[2].run_time != 0) {
				level_c = 1 + (time - data[2].in_time) * 1.0 / data[2].run_time;
			}
			//返回先执行的的下标
			int pos = findMaxLevel(data, level_a, level_b, level_c);
			//如果返回的不是-1（三者响应比都为0的情况）
			if (pos != -1) {
				while (data[pos].run_time != 0) {
					data[pos].run_time--;
					time++;
				}
				if (data[pos].run_time == 0) {
					len--;
					re_time[pos] = time - data[pos].in_time;
				}
			}
			//如果返回的是三者响应比都为0的情况
			//那么就time++知道达到某个进程的进入时间即可
			else time++;
		}
		for (int i = 0; i < 3; i++) {
			System.out.print(re_time[i] + " ");
		}
	}

	public static int findMaxLevel(Data[] data, double a, double b, double c) {
		int pos = 0;
		if (a == 0 && b == 0 && c == 0) return -1;
		//对三者响应比进行比较
		if (a >= b) {
			if (a >= c) pos = 0;
			else pos = 2;
			//b>a
		} else {
			if (b < c) pos = 2;
			else pos = 1;
		}
		//针对上述a==b,a==c,b==c的情况进行具体分析，分三种情况谁的进入时间小就返回谁的下标
		if (a == b && pos == 0) pos = data[0].in_time > data[1].in_time ? 1 : 0;
		else if (a == c && pos == 0) pos = data[0].in_time > data[2].in_time ? 2 : 0;
		else if (b == c && pos == 1) pos = data[1].in_time > data[2].in_time ? 2 : 1;
		return pos;
	}
}
